<template>
  <el-table-v2
    :columns="columns"
    :data="data"
    :width="700"
    :height="400"
    fixed
  />
</template>

<script lang="ts" setup>
import { ref } from "vue";
const excelList = ref<any[][]>([
  [
    "序号",
    "层级",
    "物料代码",
    "代号",
    "名称",
    "所属装配图号",
    "数量",
    "总数量",
    "单位",
    "材质",
    "单件重量",
    "类别",
    "备注",
  ],
  [
    1,
    null,
    "02.001.001.5416",
    "EBZ160M-2_2022-019",
    "掘锚机",
    null,
    1,
    null,
    "个",
    "组装图",
    57590.1,
    "自制件",
  ],
  [
    2,
    "1",
    "02.001.001.5017",
    "EBZ160M_2.5",
    "行走部",
    "EBZ160M-2_2022-019",
    1,
    1,
    "个",
    "组装件",
    12048,
    "自制件",
  ],
  [
    3,
    "2",
    "02.001.001.1005",
    "J18.5.1(G)",
    "左履带架",
    "EBZ160M_2.5",
    1,
    1,
    "个",
    "焊接加工件",
    20712,
    "自制件",
  ],
  [
    4,
    "3",
    "02.001.001.582",
    "J18.5.1-1",
    "平板A",
    "J18.5.1(G)",
    1,
    1,
    "个",
    "B=20/Q345",
    9.92,
    "自制件",
  ],
  [
    5,
    "3",
    "02.001.001.583",
    "J18.5.1-2",
    "堵板",
    "J18.5.1(G)",
    2,
    2,
    "个",
    "B=20/Q345",
    0.65,
    "自制件",
  ],
]);

const cols = function () {
  const args: string[] = excelList.value[0]; // 使用类型断言告诉 TypeScript args 是一个字符串数组
  let columns = [];
  for (let valueElement of args) {
    // 使用 args 作为循环条件，确保它是一个字符串数组
    columns.push({
      key: valueElement,
      dataKey: valueElement,
      title: valueElement,
      width: 150,
    });
  }
  return columns;
};
const das = function () {
  const args: string[] = excelList.value[0]; // 使用类型断言告诉 TypeScript args 是一个字符串数组
  const vals = excelList.value.slice(1);
  let columns = [];
  let values = [];
  for (let valueElement of args) {
    // 使用 args 作为循环条件，确保它是一个字符串数组
    columns.push({
      key: valueElement,
      dataKey: valueElement,
      title: valueElement,
      width: 150,
    });
  }
  for (let val of vals) {
    let value: { [key: string]: any } = {};
    for (let i = 0; i < args.length; i++) {
      value[args[i]] = val[i];
    }
    values.push(value);
  }
  return values;
};
let columns = cols();
let data = das();
</script>
